package com.wufun.overseas.tools.filetransfer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.wufun.overseas.tools.socket.entity.SocketConfig;

import org.greenrobot.eventbus.EventBus;

/**
 * Author: hest
 * Date:  2016/5/30
 * 热点状态监听
 */
public class ApWifiConnectedReceiver extends BroadcastReceiver {
    private static final String TAG=ApWifiConnectedReceiver.class.getSimpleName();
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if ("android.net.wifi.WIFI_AP_STATE_CHANGED".equals(action)) {
            Log.d(TAG, "onReceive: 连接断开");
            //便携式热点的状态为：10---正在关闭；11---已关闭；12---正在开启；13---已开启
            int state = intent.getIntExtra("wifi_state", 0);
            if (state == 11) {
                EventBus.getDefault().post(SocketConfig.SOCKET_DIS_CONNECTED);
            }
        }else if("android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED".equals(action)){
            Log.d(TAG, "onReceive: 数量");
            EventBus.getDefault().post(SocketConfig.SOCKET_DIS_CONNECTED);
        }
    }
}
